package com.gc.controller;


import com.gc.Common.result.Result;
import com.gc.Common.result.ResultUtils;
import com.gc.entity.Product;
import com.gc.entity.Type;
import com.gc.entity.User;
import com.gc.service.IProductService;
import com.gc.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Yuyingying
 * @since 2024-09-05
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    IProductService service;
    @RequestMapping("/getList")
    public Result<Product> getList(){
        List<Product> list = service.list();
        return ResultUtils.returnSuccessLayui(list,list.size());
}
    @RequestMapping("/getAllList")
    public Result<Product>getAllList(){
        return ResultUtils.returnDataSuccess(service.list());
    }
    @RequestMapping("/del")
    public Object del(Integer id){
        if (service.removeById(id)){
            return ResultUtils.returnSuccess();
        }else{
            return ResultUtils.returnFail();
        }
    }
    @RequestMapping("/add")
    public Object add(Product product) {
        if (service.save(product)) {
            return ResultUtils.returnSuccess();
        } else {
            return ResultUtils.returnFail("添加失败");
        }
    }
    @RequestMapping("/update")
    public Object update(Product product) {
        if (service.updateById(product)) {
            return ResultUtils.returnSuccess();
        } else {
            return ResultUtils.returnFail("修改失败");
        }
    }

}
